package com.lin.sunnyweather.logic.network

import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

object ServiceCreator {

    //城市信息URL
    private const val LOCATION_URL = "https://geoapi.qweather.com/"

    //天气URL
    private const val WEATHER_URL = "https://devapi.qweather.com"

    private val locationRetrofit = Retrofit.Builder()
        .baseUrl(LOCATION_URL)
        .addConverterFactory(GsonConverterFactory.create())
        .build()

    private val weatherRetrofit = Retrofit.Builder()
        .baseUrl(WEATHER_URL)
        .addConverterFactory(GsonConverterFactory.create())
        .build()

    fun <T> createLocation(serviceClass: Class<T>): T = locationRetrofit.create(serviceClass)
    fun <T> createWeather(serviceClass: Class<T>): T = weatherRetrofit.create(serviceClass)

    inline fun <reified T> createLocation(): T = createLocation(T::class.java)
    inline fun <reified T> createWeather(): T = createWeather(T::class.java)
}